package com.sailfish.springbootdemo.dao.db1;

import com.sailfish.springbootdemo.common.DB1TableName;
import com.sailfish.springbootdemo.pojo.db1.LineLevel;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface LineLevelDao {

    /**
     * 查询所有
     *
     * @return
     */
    @Results(id = "lineLevelResultMap", value = {
            @Result(column = "line_level_id", property = "lineLevelId", jdbcType = JdbcType.INTEGER),
            @Result(column = "line_level_name", property = "lineLevelName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "sort", property = "sort", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.DATETIMEOFFSET),
    })
    @Select("select * from " + DB1TableName.LINE_LEVEL + " order by sort")
    List<LineLevel> getAllLineLevel();

    /**
     * 根据id查询
     *
     * @param lineLevelId
     * @return
     */
    @Select("select * from " + DB1TableName.LINE_LEVEL + " where line_level_id = #{lineLevelId}")
    @ResultMap(value = "lineLevelResultMap")
    LineLevel getLineLevelById(@Param("lineLevelId") Integer lineLevelId);

    /**
     * in语据查询
     *
     * @param lineLevelIds
     * @return
     */
    @ResultMap(value = "lineLevelResultMap")
    @Select("<script>" +
            "select * from " + DB1TableName.LINE_LEVEL + " where 1 = 1 " +
            "<if test=\"lineLevelIds != null and lineLevelIds.size() > 0 \">\n" +
            "                and line_level_id in\n" +
            "                <foreach item=\"item\" index=\"index\" collection=\"lineLevelIds\"\n" +
            "                         open=\"(\" separator=\",\" close=\")\">\n" +
            "                    #{item}\n" +
            "                </foreach>\n" +
            "            </if>\n" +
            "</script>")
    List<LineLevel> getLineLevelByIds(@Param("lineLevelIds") List<Integer> lineLevelIds);
}
